/*
 * @Description:
 * @Author: 月间
 * @Date: 2024-10-14 21:07:53
 * @LastEditTime: 2025-10-12 00:36:35
 * @LastEditors:
 */
import { request } from '../request';

/** get role list */
export function fetchGetRoleList(params?: Api.SystemManage.RoleSearchParams) {
  return request<Api.SystemManage.RoleList>({
    url: '/system/role/list',
    method: 'get',
    params
  });
}

/**
 * get all roles
 *
 * these roles are all enabled
 */
export function fetchGetAllRoles() {
  return request<Api.SystemManage.AllRole[]>({
    url: '/system/role/getAllRoles',
    method: 'get'
  });
}
// 新增角色
export function fetchAddRole(data: Api.SystemManage.RoleUpdate) {
  return request<App.Service.Response>({
    url: '/system/role/add',
    method: 'post',
    data
  });
}
// 更新角色
export function fetchUpdateRole(data: Api.SystemManage.RoleUpdate) {
  return request<App.Service.Response>({
    url: '/system/role/update',
    method: 'put',
    data
  });
}

// 批量删除角色
export function fetchBatchDeleteRole(data: Api.SystemManage.Ids) {
  return request<App.Service.Response>({
    url: '/system/role/delete',
    method: 'delete',
    data
  });
}
// 根据角色id获取菜单id列表
export function fetchGetMenuIdsByRoleId(id: number) {
  return request<Api.SystemManage.perIds>({
    url: `/system/role/getRoleMenuIds?role_id=${id}`,
    method: 'get'
  });
}
// 修改角色权限
export function fetchUpdateRolePermissions(data: Api.SystemManage.RolePerUpdate) {
  return request<App.Service.Response>({
    url: '/system/role/update/permissions',
    method: 'put',
    data
  });
}
/** get user list */
export function fetchGetUserList(params?: Api.SystemManage.UserSearchParams) {
  return request<Api.SystemManage.UserList>({
    url: '/system/user/list',
    method: 'get',
    params
  });
}
// 新增用户
export function fetchAddUser(data: Api.SystemManage.UserUpdate) {
  return request<App.Service.Response>({
    url: '/system/user/add',
    method: 'post',
    data
  });
}

// 修改用户
export function fetchUpdateUser(data: Api.SystemManage.UserUpdate) {
  return request<App.Service.Response>({
    url: '/system/user/update',
    method: 'put',
    data
  });
}
// 批量删除用户
export function fetchBatchDeleteUser(data: Api.SystemManage.Ids) {
  return request<App.Service.Response>({
    url: '/system/user/delete',
    method: 'delete',
    data
  });
}

/** get menu list */
export function fetchGetMenuList(params?: Api.SystemManage.MenuSearchParams) {
  return request<Api.SystemManage.MenuList>({
    url: '/system/menu/list',
    method: 'get',
    params
  });
}

/** get menu detail */
export function fetchGetMenuDetail(id: number) {
  return request<Api.SystemManage.Menu>({
    url: `/system/menu/view/${id}`,
    method: 'get'
  });
}
// 新增菜单
export function fetchAddMenu(data: Api.SystemManage.MenuUpdate) {
  return request<App.Service.Response>({
    url: '/system/menu/add',
    method: 'post',
    data
  });
}

// 修改菜单
export function fetchUpdateMenu(data: Api.SystemManage.MenuUpdate) {
  return request<App.Service.Response>({
    url: '/system/menu/update',
    method: 'put',
    data
  });
}
// 批量删除菜单
export function fetchBatchDeleteMenu(data: Api.SystemManage.Ids) {
  return request<App.Service.Response>({
    url: '/system/menu/delete',
    method: 'delete',
    data
  });
}

// 查询根据菜单id查询菜单按钮
export function fetchGetMenuButton(params?: Api.SystemManage.ButtonSearchParams) {
  return request<Api.SystemManage.ButtonList>({
    url: '/system/menu/button',
    method: 'get',
    params
  });
}

// 添加菜单按钮
export function fetchAddMenuButton(data: Api.SystemManage.ButtonUpdate) {
  return request<App.Service.Response>({
    url: '/system/menu/button/add',
    method: 'post',
    data
  });
}

// 修改菜单按钮
export function fetchUpdateMenuButton(data: Api.SystemManage.ButtonUpdate) {
  return request<App.Service.Response>({
    url: '/system/menu/button/update',
    method: 'put',
    data
  });
}
// 批量删除菜单按钮
export function fetchBatchDeleteMenuButton(data: Api.SystemManage.Ids) {
  return request<App.Service.Response>({
    url: '/system/menu/button/delete',
    method: 'delete',
    data
  });
}
// 查询所有菜单按钮
export function fetchGetAllMenuButton() {
  return request<Api.SystemManage.MenuButton[]>({
    url: '/system/menu/buttons',
    method: 'get'
  });
}
/** get all pages */
export function fetchGetAllPages() {
  return request<string[]>({
    url: '/system/menu/getAllPages',
    method: 'get'
  });
}

/** get all menus */
export function fetchGetAllMenus() {
  return request<Api.SystemManage.Menu[]>({
    url: '/system/menu/all',
    method: 'get'
  });
}

/** get menu tree */
export function fetchGetMenuTree() {
  return request<Api.SystemManage.MenuTree[]>({
    url: '/system/menu/options',
    method: 'get'
  });
}

/** 岗位列表 */
export function fetchGetPostList(params?: Api.SystemManage.PostSearchParams) {
  return request<Api.SystemManage.PostList>({
    url: '/system/post/list',
    method: 'get',
    params
  });
}
// 所有岗位
export function fetchGetAllPost() {
  return request<CommonType.Option[]>({
    url: '/system/post/all',
    method: 'get'
  });
}

/** 新增岗位 */
export function fetchAddPost(data: Api.SystemManage.PostUpdate) {
  return request<App.Service.Response>({
    url: '/system/post/add',
    method: 'post',
    data
  });
}
/** 更新岗位 */
export function fetchUpdatePost(data: Api.SystemManage.PostUpdate) {
  return request<App.Service.Response>({
    url: '/system/post/update',
    method: 'put',
    data
  });
}
/** 删除岗位 */
export function fetchBatchDeletePost(data: Api.SystemManage.Ids) {
  return request<App.Service.Response>({
    url: '/system/post/delete',
    method: 'delete',
    data
  });
}

/** 获取部门列表 */
export function fetchGetDepartmentList() {
  return request<Api.SystemManage.DeptList>({
    url: '/system/dept/list',
    method: 'get'
  });
}
/** 获取部门树 */
export function fetchGetDepartmentTree() {
  return request<Api.SystemManage.Dept[]>({
    url: '/system/dept/tree',
    method: 'get'
  });
}

/** 添加部门 */
export function fetchAddDepartment(data: Api.SystemManage.DeptUpdate) {
  return request<App.Service.Response>({
    url: '/system/dept/add',
    method: 'post',
    data
  });
}

/** 修改部门 */
export function fetchUpdateDepartment(data: Api.SystemManage.DeptUpdate) {
  return request<App.Service.Response>({
    url: '/system/dept/update',
    method: 'put',
    data
  });
}

/** 删除部门 */
export function fetchBatchDeleteDepartment(data: Api.SystemManage.Ids) {
  return request<App.Service.Response>({
    url: '/system/dept/delete',
    method: 'delete',
    data
  });
}
// 字典列表
export function fetchGetDictList(params?: Api.SystemManage.DictTypeSearchParams) {
  return request<Api.SystemManage.DictTypeList>({
    url: '/system/dict/type/list',
    method: 'get',
    params
  });
}
// 添加字典类型
export function fetchAddDictType(data: Api.SystemManage.DictTypeUpdate) {
  return request<App.Service.Response>({
    url: '/system/dict/type/add',
    method: 'post',
    data
  });
}
// 修改字典类型
export function fetchUpdateDictType(data: Api.SystemManage.DictTypeUpdate) {
  return request<App.Service.Response>({
    url: '/system/dict/type/update',
    method: 'put',
    data
  });
}
// 删除字典类型
export function fetchDeleteDictType(data: Api.SystemManage.Ids) {
  return request<App.Service.Response>({
    url: '/system/dict/type/delete',
    method: 'delete',
    data
  });
}

// 字典数据查询
export function fetchGetDictDataList(dict_id: number) {
  return request<Api.SystemManage.DictData[]>({
    url: `/system/dict/data/${dict_id}/list`,
    method: 'get'
  });
}

// 添加字典数据
export function fetchAddDictData(data: Api.SystemManage.DictDataUpdate) {
  return request<App.Service.Response>({
    url: '/system/dict/data/add',
    method: 'post',
    data
  });
}
// 修改字典数据
export function fetchUpdateDictData(data: Api.SystemManage.DictTypeUpdate) {
  return request<App.Service.Response>({
    url: '/system/dict/data/update',
    method: 'put',
    data
  });
}

// 删除字典数据
export function fetchDeleteDictData(id: number) {
  return request<App.Service.Response>({
    url: `/system/dict/data/delete/${id}`,
    method: 'delete'
  });
}
// 获取字典键值对
export function fetchGetDictMap(keys: string[]) {
  return request<Api.SystemManage.DictOption>({
    url: '/system/dict/options',
    method: 'post',
    data: keys
  });
}
// 获取系统信息
export function fetchGetSystemInfo() {
  return request<Api.SystemManage.ServerMonitorModel>({
    url: '/monitor/server',
    method: 'get'
  });
}

// 查询缓存仪表图
export function fetchGetCacheGauge() {
  return request<App.Service.Response>({
    url: '/monitor/cache/gauge',
    method: 'get'
  });
}
// redis命令饼状图
export function fetchGetCachePie() {
  return request<App.Service.Response>({
    url: '/monitor/cache/pie',
    method: 'get'
  });
}
export function fetchGetCacheInfo() {
  return request<App.Service.Response>({
    url: '/monitor/cache/info',
    method: 'get'
  });
}
// 定时列表查询
export function fetchGetTaskList(params: Api.SystemManage.TaskSearchParams) {
  return request<Api.SystemManage.TaskList>({
    url: '/task/list',
    method: 'get',
    params
  });
}

// 添加定时任务
export function fetchAddTask(data: Api.SystemManage.TaskUpdate) {
  return request<App.Service.Response>({
    url: '/task/add',
    method: 'post',
    data
  });
}

// 更新定时任务
export function fetchUpdateTask(data: Api.SystemManage.TaskUpdate) {
  return request<App.Service.Response>({
    url: '/task/update',
    method: 'put',
    data
  });
}

// 删除定时任务
export function fetchDeleteTask(data: Api.SystemManage.Ids) {
  return request<App.Service.Response>({
    url: '/task/delete',
    method: 'delete',
    data
  });
}
// 修改状态
export function fetchUpdateTaskStatus(data: Api.SystemManage.TaskStatus) {
  return request<App.Service.Response>({
    url: '/task/change/status',
    method: 'put',
    data
  });
}

// 资源列表查询
export function fetchGetResourceList(params: Api.SystemManage.ResourceSearchParams) {
  return request<Api.SystemManage.ResourceList>({
    url: '/system/resource/list',
    method: 'get',
    params
  });
}

// 资源上传
export function fetchUploadResource(data: FormData) {
  return request<App.Service.Response>({
    url: '/system/resource/upload',
    method: 'post',
    data
  });
}

// 删除资源
export function fetchDeleteResource(data: Api.SystemManage.Ids) {
  return request<App.Service.Response>({
    url: '/system/resource/delete',
    method: 'delete',
    data
  });
}

// 登录日志列表查询
export function fetchGetLoginLogList(params: Api.SystemManage.LoginRecordSearchParams) {
  return request<Api.SystemManage.LoginRecordList>({
    url: '/system/record/login/list',
    method: 'get',
    params
  });
}

// 操作日志
export function fetchGetOperateLogList(params: Api.SystemManage.OperationRecordSearchParams) {
  return request<Api.SystemManage.OperationRecordList>({
    url: '/system/record/operate/list',
    method: 'get',
    params
  });
}

// 任务日志
export function fetchGetTaskLogList(params: Api.SystemManage.FuncBoostRecordSearchParams) {
  return request<Api.SystemManage.FuncBoostRecordList>({
    url: '/task/record/list',
    method: 'get',
    params
  });
}
// 获取所有任务名称
export function fetchGetTaskName() {
  return request<CommonType.Option<string>[]>({
    url: '/task/job/all',
    method: 'get'
  });
}

// 获取所有运行中消费者
export function fetchGetOnlineConsumers(params: Api.SystemManage.ConsumerSearchParams) {
  return request<Api.SystemManage.ConsumerList>({
    url: '/task/heartbeat/queue',
    method: 'get',
    params
  });
}
// 获取在线用户列表
export function fetchGetOnlineUsers() {
  return request<Api.SystemManage.SimpleOnlineUser[]>({
    url: '/system/user/online/users',
    method: 'get'
  });
}

// 获取用户设备信息
export function fetchGetUserDevices(user_id: number) {
  return request<Api.SystemManage.TerminalInfoModel[]>({
    url: `/system/user/online/user/${user_id}/devices`,
    method: 'get'
  });
}

// 根据token注销用户
export function fetchLogoutByToken(token: string) {
  return request<App.Service.Response>({
    url: '/system/user/online/logout-by-token',
    method: 'post',
    params: { token }
  });
}

// 根据login_id强制下线用户
export function fetchLogoutByLoginId(login_id: number) {
  return request<App.Service.Response>({
    url: '/system/user/online/logout-by-login-id',
    method: 'post',
    params: { login_id }
  });
}

// 根据token封禁用户
export function fetchDisable(login_id: string, time: number = -1) {
  return request<App.Service.Response>({
    url: '/system/user/online/disable',
    method: 'post',
    params: { login_id, time }
  });
}

// 队列列表
export function fetchGetQueueList(params: Api.SystemManage.QueueSearchParams) {
  return request<Api.SystemManage.QueueList>({
    url: '/task/queue/list',
    method: 'get',
    params
  });
}
// 暂停消费
export function fetchPauseConsumer(queue_name: string) {
  return request<App.Service.Response>({
    url: `/task/queue/pause?queue_name=${queue_name}`,
    method: 'post'
  });
}
// 恢复消费
export function fetchResumeConsumer(queue_name: string) {
  return request<App.Service.Response>({
    url: `/task/queue/resume?queue_name=${queue_name}`,
    method: 'post'
  });
}
// 清空消息
export function fetchClearQueue(broker_kind: string, queue_name: string) {
  return request<App.Service.Response>({
    url: `/task/queue/clear?queue_name=${queue_name}&broker_kind=${broker_kind}`,
    method: 'post'
  });
}
// 获取消费统计图
export function fetchGetConsumerStatistics(queue_name: string, time_type: string) {
  return request<App.Service.Response>({
    url: `/task/queue/statistics?task_name=${queue_name}&time_type=${time_type}`,
    method: 'get'
  });
}
// 获取运行中的队列
export function fetchGetConsumerOptions() {
  return request<CommonType.Option<string>[]>({
    url: '/task/consumers/options',
    method: 'get'
  });
}
